package com.njust.dao;

import static com.njust.dao.CatDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.njust.bean.Cat;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface CatMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.116+08:00", comments="Source Table: t_cat")
    BasicColumn[] selectList = BasicColumn.columnList(id, cname, cage, cgender);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.091+08:00", comments="Source Table: t_cat")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.093+08:00", comments="Source Table: t_cat")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.094+08:00", comments="Source Table: t_cat")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<Cat> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.096+08:00", comments="Source Table: t_cat")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<Cat> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.097+08:00", comments="Source Table: t_cat")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("CatResult")
    Optional<Cat> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.099+08:00", comments="Source Table: t_cat")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="CatResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="cName", property="cname", jdbcType=JdbcType.VARCHAR),
        @Result(column="cAge", property="cage", jdbcType=JdbcType.INTEGER),
        @Result(column="cGender", property="cgender", jdbcType=JdbcType.INTEGER)
    })
    List<Cat> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.102+08:00", comments="Source Table: t_cat")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.103+08:00", comments="Source Table: t_cat")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, cat, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.104+08:00", comments="Source Table: t_cat")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, cat, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.107+08:00", comments="Source Table: t_cat")
    default int deleteByPrimaryKey(Integer id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.108+08:00", comments="Source Table: t_cat")
    default int insert(Cat record) {
        return MyBatis3Utils.insert(this::insert, record, cat, c ->
            c.map(id).toProperty("id")
            .map(cname).toProperty("cname")
            .map(cage).toProperty("cage")
            .map(cgender).toProperty("cgender")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.111+08:00", comments="Source Table: t_cat")
    default int insertMultiple(Collection<Cat> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, cat, c ->
            c.map(id).toProperty("id")
            .map(cname).toProperty("cname")
            .map(cage).toProperty("cage")
            .map(cgender).toProperty("cgender")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.113+08:00", comments="Source Table: t_cat")
    default int insertSelective(Cat record) {
        return MyBatis3Utils.insert(this::insert, record, cat, c ->
            c.map(id).toPropertyWhenPresent("id", record::getId)
            .map(cname).toPropertyWhenPresent("cname", record::getCname)
            .map(cage).toPropertyWhenPresent("cage", record::getCage)
            .map(cgender).toPropertyWhenPresent("cgender", record::getCgender)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.12+08:00", comments="Source Table: t_cat")
    default Optional<Cat> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, cat, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.121+08:00", comments="Source Table: t_cat")
    default List<Cat> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, cat, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.122+08:00", comments="Source Table: t_cat")
    default List<Cat> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, cat, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.123+08:00", comments="Source Table: t_cat")
    default Optional<Cat> selectByPrimaryKey(Integer id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.125+08:00", comments="Source Table: t_cat")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, cat, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.126+08:00", comments="Source Table: t_cat")
    static UpdateDSL<UpdateModel> updateAllColumns(Cat record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalTo(record::getId)
                .set(cname).equalTo(record::getCname)
                .set(cage).equalTo(record::getCage)
                .set(cgender).equalTo(record::getCgender);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.128+08:00", comments="Source Table: t_cat")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Cat record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalToWhenPresent(record::getId)
                .set(cname).equalToWhenPresent(record::getCname)
                .set(cage).equalToWhenPresent(record::getCage)
                .set(cgender).equalToWhenPresent(record::getCgender);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.131+08:00", comments="Source Table: t_cat")
    default int updateByPrimaryKey(Cat record) {
        return update(c ->
            c.set(cname).equalTo(record::getCname)
            .set(cage).equalTo(record::getCage)
            .set(cgender).equalTo(record::getCgender)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-04-04T20:34:15.132+08:00", comments="Source Table: t_cat")
    default int updateByPrimaryKeySelective(Cat record) {
        return update(c ->
            c.set(cname).equalToWhenPresent(record::getCname)
            .set(cage).equalToWhenPresent(record::getCage)
            .set(cgender).equalToWhenPresent(record::getCgender)
            .where(id, isEqualTo(record::getId))
        );
    }
}